#include<bits/stdc++.h>
using namespace std;
struct st{int d,v,a;}c[114514];
struct ar{int l,r;}qj[114514];
int t,n,m,l,v,p[114514],ni[1919810],nc[1919810],mna,att,tot,ans1,ans2,cnt,cs[114514];
int delv(int v0,int a,int s){
    double r=1.0*v0*v0+2.0*a*s;
    if(r>0.0)r=1.0*sqrt(1.0*r);
    else r=0.0;
    return ceil(r);
}
int ovspp(int d,int v0,int a){
    double r=(v*v-v0*v0)/2.0/a;
    if(r>l)return l+1;
    return min(l,d+max(0,(int)floor(r)));
}
bool ok(){
    bool fl;
    for(int i=1;i<=cnt;i++){
        fl=qj[i].l>qj[i].r;
        for(int j=qj[i].l;j<=qj[i].r;j++)if(cs[j]){fl=1;break;}
        if(!fl)return 0;
    }return 1;
}
void dfs(int d,int x){
    if(d==m){if(ok()&&ans2>x)ans2=x;return;}
    dfs(d+1,x);
    cs[d+1]=1;
    dfs(d+1,x+1);
    cs[d+1]=0;
}
int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    cin>>t;
    while(t--){
        mna=1000,att=1,cnt=tot=ans1=0;
        cin>>n>>m>>l>>v;
        for(int i=1;i<=n;i++)cin>>c[i].d>>c[i].v>>c[i].a,mna=min(mna,c[i].a),att*=(c[i].a+1),tot+=c[i].a;
        for(int i=1;i<=m;i++)cin>>p[i];
        for(int i=1;i<=m;i++)for(int j=p[i-1]+1;j<=p[i];j++)nc[j]=p[i],ni[j]=i;
        for(int i=p[m]+1;i<=l+10;i++)nc[i]=-1,ni[i]=m+1;
        for(int i=1;i<=n;i++)if(!c[i].a)ans1+=(c[i].v>v&&nc[c[i].d]+1);
        else if(c[i].a>0)ans1+=(nc[c[i].d]+1&&delv(c[i].v,c[i].a,p[m]-c[i].d)>v);
        else ans1+=(nc[c[i].d]+1&&delv(c[i].v,c[i].a,nc[c[i].d]-c[i].d)>v);
        cout<<ans1<<" ";
        if((att==1&&!tot)||(mna>0)){
            cout<<m-1;
        }else{
            ans2=4000;
            for(int i=1;i<=n;i++){
                if(c[i].a>0&&(nc[c[i].d]+1&&delv(c[i].v,c[i].a,p[m]-c[i].d)>v))qj[++cnt]={ni[ovspp(c[i].d,c[i].v,c[i].a)+1],m};
                if(c[i].a<0&&(nc[c[i].d]+1&&delv(c[i].v,c[i].a,nc[c[i].d]-c[i].d)>v))qj[++cnt]={ni[c[i].d],ni[ovspp(c[i].d,c[i].v,c[i].a)]-1};
                if(!c[i].a&&(c[i].v>v&&nc[c[i].d]+1))qj[++cnt]={ni[c[i].d],m};
            }
            dfs(0,0);
            cout<<m-ans2;
        }cout<<"\n";
    }
    return 0;
}
